package com.zidian.study.utils;

import java.util.ArrayList;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.zidian.student.trucks.R;

/**
 * <p>
 * class desc: 底部的对话框 动态配置 适配器
 * <p/>
 * </p>
 */
public class BottomDialogAdapter extends BaseAdapter {

    ArrayList<BottomDialogEntity> bottomDialogEntities;
    /***
     * 上下文对象
     */
    protected Context context;

    public BottomDialogAdapter(Context context,
                               ArrayList<BottomDialogEntity> bottomDialogEntities) {
        this.bottomDialogEntities = bottomDialogEntities;
        this.context = context;
    }

    @Override
    public int getCount() {
        // TODO Auto-generated method stub
        return bottomDialogEntities.size();
    }

    @Override
    public Object getItem(int position) {
        // TODO Auto-generated method stub
        return bottomDialogEntities.get(position);
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        // TODO Auto-generated method stub
        BottomDialogEntity bottomDialogEntity = (BottomDialogEntity) getItem(position);
        ViewHolder viewHolder = null;
        if (convertView == null) {
            convertView = View.inflate(context, R.layout.global_bottom_dialog_item, null);
            viewHolder = new ViewHolder();
            TextView content = (TextView) convertView.findViewById(R.id.dialogItemClick);
            viewHolder.content = content;
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }

        viewHolder.content.setText(bottomDialogEntity.getContent());

        return convertView;
    }

    class ViewHolder {
        TextView content;
    }

}
